class animateNumber {
        constructor(id,startNum,height){
            this.id = id//容器唯一标识
            this.startNum = startNum // 初始数值
			this.height=height
            this.savePositionArr = [] //存放旧数据的位置数组
        }

        // 数字转成数组
        number2Arr(digit){
            var num_arr=[];
            for(var i = 0;i<digit.length;i++){
                num_arr.push(digit.charAt(i));
            }
            return num_arr;
        }

        // dom构建
        amtDom(arr){
            var str = '';
            for(var i = 0;i<arr.length;i++){
                if(parseInt(arr[i])>=0){
                    str += '<div style="display: flex;flex-direction: column;line-height: '+this.height+'px;" class="scrollItem digit-container" data-show='+arr[i]+'>\
                            <span>0</span>\
                            <span>1</span>\
                            <span>2</span>\
                            <span>3</span>\
                            <span>4</span>\
                            <span>5</span>\
                            <span>6</span>\
                            <span>7</span>\
                            <span>8</span>\
                            <span>9</span>\
                        </div>';
                }else{
                    str += '<div class="sign-box" style="line-height:'+this.height+'px"><span>'+arr[i]+'</span></div>';
                }
            }
            return str;
        }

        // 将数字转换为逗号隔开的千分位格式
        num2qfw(num){
            num += '';
            if (!num.includes('.')) num += '.';
            return num.replace(/(\d)(?=(\d{3})+\.)/g, function($0, $1) {
                return $1 + ',';
            }).replace(/\.$/, '')
        }

        animation(){
            const _this = this
            $("#"+_this.id+" .scrollItem").each(function(i){
                let scrollTopOld,scrollTopNew;
                let num = parseInt($(this).data("show"));
                scrollTopNew = _this.height * num;
                if(!_this.savePositionArr[i]){
                    _this.savePositionArr[i] = 0
                }
                scrollTopOld = _this.savePositionArr[i];
                $(this).css("margin-top",-scrollTopOld);
                if(scrollTopOld != scrollTopNew){
                    $(this).animate({marginTop: -scrollTopNew},1000);
                }

                _this.savePositionArr[i] = scrollTopNew
            });
        }

        init(){
            const _sNum = this.num2qfw(this.startNum)
            const numArr = this.number2Arr(_sNum);
            $("#" + this.id).html(this.amtDom(numArr));
            this.animation();
        }
    }
